from playwright.sync_api import Page


class RyRegisterPage:

    def __init__(self, page: Page):
        self.page = page

        self.username = page.get_by_role("textbox", name="用户名")

        self.password1 = page.get_by_role("textbox", name="密码", exact=True)
        self.password2 = page.get_by_role("textbox", name="确认密码")

        self.checkbox = page.get_by_role("checkbox", name="我已阅读并同意")
        self.register_btn = page.get_by_role("button", name="注册")

        self.alert_tips_register = page.get_by_text("当前系统没有开启注册功能！")

    def navigate(self, url='/register'):
        self.page.goto(url)

    def fill_username(self, username):
        self.username.click()
        self.username.fill(username)

    def fill_password1(self, password1):
        self.password1.click()
        self.password1.fill(password1)

    def fill_password2(self, password2):
        self.password2.click()
        self.password2.fill(password2)

    def click_checkbox(self):
        self.checkbox.click()

    def click_register_btn(self):
        self.register_btn.click()

    def flow_register(self, username, password1, password2):
        self.navigate()
        self.fill_username(username)
        self.fill_password1(password1)
        self.fill_password2(password2)
        self.click_checkbox()
